package com.hjl.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Date;

/**
 * @author ServivE
 * @version 0.1
 * @className MyhttpSessionListener
 * @description
 * @date 2024/7/26 19:40
 * @since jdk11
 */
//监听Httpsession域的创建于销毁的监听器HttpSessionListener
@WebListener
public class MyhttpSessionListener implements HttpSessionListener {
    public void sessionCreated(HttpSessionEvent hse) {
        String beginTime = new Date().toString();
        HttpSession session = hse.getSession();
        System.out.println(beginTime + "：创建了session，" + session.getId());
    }
    public void sessionDestroyed(HttpSessionEvent hse) {
        String endTime = new Date().toString();
        HttpSession session = hse.getSession();
        System.out.println(endTime + "：销毁了session，" + session.getId());
    }
}
